package com.example.homework08.sqliteroom;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(entities = {User.class}, version = 1)
public abstract class MyRoomDatabase extends RoomDatabase {
    private static MyRoomDatabase instance;

    public abstract UserDao userDao();

    static MyRoomDatabase getInstance(Context context){
        if(instance == null) {
            instance = Room.databaseBuilder(context.getApplicationContext(), MyRoomDatabase.class,"room")
//            这里为了测试允许在主线程中使用R0Om库
//            但正式的应用不要这样用数据库操作时会大U界面
//            建议得数据库操作改成异步的
            .allowMainThreadQueries().build();
        }
        return instance;
    }
}
